package com.hnu.store.utils;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * Json格式进行数据的响应
 */
public class JsonResult implements Serializable {

  // 返回状态码
  private Integer code;
  // 返回信息
  private String message;
  // 返回数据集
  private Map<String, Object> data = new HashMap<>();

  public JsonResult(Integer code) {
    this.code = code;
  }

  public JsonResult(Throwable e) {
    this.message = e.getMessage();
  }

  public JsonResult addData(String key, Object value) {
    this.data.put(key, value);
    return this;
  }

  public Integer getCode() {
    return code;
  }

  public void setCode(Integer code) {
    this.code = code;
  }

  public String getMessage() {
    return message;
  }

  public void setMessage(String message) {
    this.message = message;
  }

  public Map<String, Object> getData() {
    return data;
  }

  public void setData(Map<String, Object> data) {
    this.data = data;
  }
}
